Skip to content

feat(engine): Add speech bubble and thinking indicator - #127

Merged
omesser merged 8 commits into
mainfrom
cursor/speech-bubble-thinking-indicator-8c35
Aug 31, 2026
Merged

omesser merged 8 commits into
mainfrom
cursor/speech-bubble-thinking-indicator-8c35

Conversation

@omesser

@omesser omesser commented Aug 31, 2026 •

Copy link
Copy Markdown
Owner

What

Speech and thinking bubbles over the sprite. A say: / speak line latches in the overlay for reading time; a reactive Director turn shows a CSS ellipsis after a short grace. Dialogue with an empty Behavior plays talk.

Why

The pipeline already emits Frame.dialogue for one tick and already knows when a session wake is in flight. Neither reached a pixel. #119 takes the bubble out of #17 (chat window stays there).

Empty-behavior dialogue plays talk for PRIMITIVE_MS (600ms). Bubble reading time (900ms + 55ms per character, clamped to 2–8s) is independent of that hold. Grace and min-hold live in the webview so the Engine stays tick-pure. Ambient wakes stay invisible. Per-Character bubble styling is not in this change.

Look

Speech (BMO, overlay chrome from this PR):

speech-bubble

Thinking ellipsis while a reactive turn is in flight:

thinking-bubble

How to test

  • Dialogue with no Behavior plays talk for the primitive hold, and still carries the line
  • Dialogue with a named Behavior plays that Behavior, not talk
  • A Behavior with no dialogue does not start talk
  • Reading time is 900ms + 55ms per character, clamped to 2–8s
  • Text wraps at max width and truncates past 6 lines with an ellipsis
  • Placement stays above the sprite, flips below near the ceiling, and stays inside display bounds

Addresses #119. Chat window remains #17.

cursoragent and others added 6 commits August 31, 2026 14:33
Speech bubbles display dialogue above the sprite, held for reading time
(900ms + 55ms per character, clamped to 2–8s). Thinking ellipsis appears
during reactive Director turns after 250ms grace, with 600ms min-hold.

Engine decision: dialogue with empty behavior plays talk for PRIMITIVE_MS
(600ms), independent of bubble duration. Bubbles follow walking sprite,
mirror correctly, stay whole across display seams, and clamp to display
bounds.

Under DND nothing appears. Hide hotkey removes bubble and sprite together,
instantly.

Tests added:
- Engine: dialogue-with-empty-behavior plays talk
- Engine: dialogue-with-playable-behavior plays the behavior
- Engine: behavior-without-dialogue does not play talk
- JS: bubble duration, wrapping, placement, clamping

Addresses #119.

Co-authored-by: Oded Messer <odedmesser@gmail.com>
CI fixes:
- Fix cargo fmt (collapsible_if, formatting)
- Fix trailing whitespace in src files

Spec gap fixes per review:

1. displayBounds ReferenceError: Moved displayBounds declaration to outer
   scope in updateBubbles() so showThinkingBubble() can access it from
   grace timeout.

2. Dialogue can be missed: Call updateBubbles() on every frame event, not
   only when art changes. Frame.dialogue is one-tick and must be latched
   regardless of animation change.

3. Bubble follows walking sprite: Reposition both speech and thinking
   bubbles every rAF using interpolated sprite position, not only on art
   change. Visible bubbles now track the sprite continuously.

4. Hide/fade: Properly handle opacity transitions without skipping.
   Instant hide (fade_ms=0) clears thinking latch. Delayed hidden class
   add prevents visibility snap during fade.

5. Thinking split: Use reactive flag only (Poke, Summon, Throw). Removed
   Grab and Perch from thinking gate per spec - only reactive session
   wakes show thinking, ambient stays invisible.

6. Tail pointing at head: Added CSS ::after pseudo-element tail (triangle
   pointing down from bubble, flipped when near ceiling). Tail stays
   centered on bubble which slides at edges.

7. Repoint docs: Updated as_speech and SPEC to say empty Behavior +
   dialogue "plays talk", not "starts nothing".

8. wrapText measureFn: Pass real ctx.measureText.bind(ctx) in browser;
   tests already use explicit measureFn (8px/char Node fallback).

9. Ceiling-flip test: Assert unconditionally - spriteRect.y < clearance
   was always true for the fixture.

All 290 core tests pass. All 14 JS tests pass.

Co-authored-by: Oded Messer <odedmesser@gmail.com>
Hard fixes:
- Fix as_speech and SPEC to state Engine plays `talk` (not "starts nothing")
- Strip restating comments and JSDoc in bubble.js
- Delete empty if (thinkingMinHoldTimeout) branch

Judgement fixes:
- Add thinking ellipsis to CONTEXT.md Expression glossary
- Export CEILING_CLEARANCE constant (128) from bubble.js
- Deduplicate bubble positioning via positionBubble() helper
- Pass explicit measureFn from main.js and tests
- Thinking gate: use ctx.happened != Ambient (not enumerated variants)
- All tests green

Co-authored-by: Oded Messer <odedmesser@gmail.com>
Co-authored-by: Oded Messer <odedmesser@gmail.com>
Co-authored-by: Oded Messer <odedmesser@gmail.com>
1. Latch behind art-change early return:
   - Move latch logic before placement check in draw()
   - Track lastLatchedDialogue/lastLatchedThinking to run once per change
   - Thinking grace starts even when art unchanged (e.g. Summon while idle)

2. Hide sticks style.opacity forever:
   - Clear inline opacity when visible (set to empty string)
   - Use fade_ms from latest instead of hardcoded 300ms

3. Tail vs edge:
   - placeBubble() returns tailOffset (spriteCenterX - bubbleCenterX)
   - CSS uses --tail-offset variable in transform
   - Tail points at sprite even when bubble clamped to edge

Tests updated to verify tailOffset calculation.

Co-authored-by: Oded Messer <odedmesser@gmail.com>
@omesser
omesser marked this pull request as ready for review August 31, 2026 15:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants